package eg.backend.query;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import eg.backend.domain.Dimension;
import eg.backend.util.TimeDimension;

public class QueryDefinition {
	private Date startDate;	
	private Date endDate;
	private String user;
	private String name;
	private TimeDimension timeDimension;
	private List<Dimension> dimensions = new ArrayList<Dimension>();	
	private Dimension viewBy;//null means time
	private String tag;
	private String shop;
	private List<String> excludedDimensions = new ArrayList<String>();
	
	public void updateConstraint(Dimension newDimension) {
		Dimension todelete = null;
		String root = newDimension.getRootDimension();
		if(root == null)
			root = newDimension.getEncodedKey();
		for(Dimension dimension : getDimensions()) {
			String root1 = dimension.getRootDimension();
			if(root1 == null)
				root1 = dimension.getEncodedKey();
			if(root1.equals(root)) {
				todelete = dimension;
				break;
			}
		}
		if(todelete != null) {
			getDimensions().remove(todelete);
			getDimensions().add(newDimension);
		}
	}
	
	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public TimeDimension getTimeDimension() {
		return timeDimension;
	}

	public void setTimeDimension(TimeDimension timeDimension) {
		this.timeDimension = timeDimension;
	}

	public void addDimension(Dimension dimension) {
		this.dimensions.add(dimension);
	}
	
	public List<Dimension> getDimensions() {
		return dimensions;
	}

	public void setDimensions(List<Dimension> dimensions) {
		this.dimensions = dimensions;
	}

	public Dimension getViewBy() {
		return viewBy;
	}

	public void setViewBy(Dimension viewBy) {
		this.viewBy = viewBy;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public String getShop() {
		return shop;
	}

	public void setShop(String shop) {
		this.shop = shop;
	}

	public List<String> getExcludedDimensions() {
		return excludedDimensions;
	}

	public void setExcludedDimensions(List<String> excludedDimensions) {
		this.excludedDimensions = excludedDimensions;
	}
	
}
